package solution._0110._0116;

import common.Node;

/**
 * Created by chen_snow
 * Date: 2021/6/29 22:08
 * Description:  填充每个节点的下一个右侧节点指针
 */
public class Solution {
    public Node connect(Node root) {
        if (root == null) {
            return null;
        }
        doConnect(root.left, root.right);
        return root;
    }

    public void doConnect(Node left, Node right) {
        if (left == null) {
            return;
        }

        left.next = right;
        doConnect(right.left, right.right);
        doConnect(left.right, right.left);
        doConnect(left.left, left.right);
    }


}
